package pro.spring.controller.backController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import pro.spring.model.Admin;

@Controller
@RequestMapping("/logins")
public class LoginsController extends BaseController{
	
	@RequestMapping(value="login",method=RequestMethod.GET)
	public String loginyemian(){
		return "page/back/login/login";
	}
	
	@RequestMapping(value="out",method=RequestMethod.GET)
	public String out(HttpServletRequest request,
			HttpServletResponse response){
		HttpSession session=request.getSession();
		session.setAttribute("aId", "");
		session.setAttribute("aAccount","");
		session.setAttribute("aName", "");
		return "redirect:login.html";
	}
	
	@ResponseBody
	@RequestMapping(value="login.json",method=RequestMethod.POST)
	public Integer login(String name,String pass,HttpServletRequest request,
			HttpServletResponse response){
		HttpSession session=request.getSession();
		System.out.println(name+"_aaaaaaaaaa_"+pass);
		Integer num = 0;
		Admin admin = adminService.selectLogin(name, pass);
		if(admin!=null){
			session.setAttribute("aName",admin.getaName());
			session.setAttribute("aAccount", admin.getaAccount());
			session.setAttribute("aId",admin.getaId());
			num = 1;
		}
		return num;
	}
}
